//
// Created by hjie on 23-7-23.
//

#include "aac_attr.h"

std::map<int, std::string> AACAttr::m_audio_object_type_map;
std::map<int, int> AACAttr::m_sample_frequency_index_map;
std::map<int, std::string> AACAttr::m_channel_configuration_map;
std::map<int, std::string> AACAttr::m_id_map;

AACAttr AACAttr::s_m_attr;

AACAttr::AACAttr()
{
    RegisterAudioObjectTye();
    RegisterSampleFrequencyIndex();
    RegisterChannelConfiguration();
    RegisterAACID();
}

void AACAttr::RegisterAudioObjectTye()
{
    m_audio_object_type_map[1] = "AAC MAIN";
    m_audio_object_type_map[2] = "AAC LC";
    m_audio_object_type_map[3] = "AAC SSR";
    m_audio_object_type_map[4] = "AAC LTP";
    m_audio_object_type_map[5] = "SBR";
}

void AACAttr::RegisterSampleFrequencyIndex()
{
    m_sample_frequency_index_map[0] = 96000;
    m_sample_frequency_index_map[1] = 88200;
    m_sample_frequency_index_map[2] = 64000;
    m_sample_frequency_index_map[3] = 48000;
    m_sample_frequency_index_map[4] = 44100;
    m_sample_frequency_index_map[5] = 32000;
    m_sample_frequency_index_map[6] = 24000;
    m_sample_frequency_index_map[7] = 16000;
    m_sample_frequency_index_map[8] = 12000;
    m_sample_frequency_index_map[9] = 11025;
    m_sample_frequency_index_map[0x10] = 8000;
}

void AACAttr::RegisterChannelConfiguration()
{
    m_channel_configuration_map[1] = "center";
    m_channel_configuration_map[2] = "stereo";
    m_channel_configuration_map[3] = "center,left,right front";
}

void AACAttr::RegisterAACID()
{
    m_id_map[0] = "MPEG-4";
    m_id_map[1] = "MPEG-2";
}

std::string AACAttr::GetAudioObjectType(int type)
{
    auto iter = m_audio_object_type_map.find(type);
    return iter != m_audio_object_type_map.end() ? iter->second : "";
}

int AACAttr::GetSampleFrequencyIndex(int index)
{
    auto iter = m_sample_frequency_index_map.find(index);
    return iter != m_sample_frequency_index_map.end() ? iter->second : 0;
}

std::string AACAttr::GetChannelConfiguration(int channel_num)
{
    auto iter = m_channel_configuration_map.find(channel_num);
    return iter != m_channel_configuration_map.end() ? iter->second : "";
}

std::string AACAttr::GetId(int index)
{
    auto iter = m_id_map.find(index);
    return iter != m_id_map.end() ? iter->second : "";
}

